package com.tre.jdevtemplateboot.common.dto;

import com.tre.jdevtemplateboot.common.constant.SysConstantToken;
import com.tre.jdevtemplateboot.common.enums.ExceptionHandlerEnums;
import com.tre.jdevtemplateboot.exception.global.SysBusinessException;

import java.io.Serializable;

/**
 * @author JDev
 */
public class ResponseResult<T> implements Serializable {

    public ResponseResult() {
    }

    private int status = 200;
    private int code = 200;
    private String msg;
    private T data;

    public ResponseResult(String msg) {
        this.msg = msg;
    }

    public ResponseResult(String msg, T data) {
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult(int status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult(int status, int code, String msg) {
        this.status = status;
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(int status, int code, String msg, T data) {
        this.status = status;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResponseResult buildOK() {
        return new ResponseResult(SysConstantToken.SERVER_SUCCESS_MSG);
    }

    public static ResponseResult buildOK(Object data) {
        return new ResponseResult(SysConstantToken.SERVER_SUCCESS_MSG, data);
    }

    public static ResponseResult buildOK(String msg, Object data) {
        return new ResponseResult(msg, data);
    }

    public static ResponseResult buildOK(int status, int code, String msg, Object data) {
        return new ResponseResult(status, code, msg, data);
    }

    public static ResponseResult buildError() {
        return new ResponseResult(200, 500, ExceptionHandlerEnums.SERVER_INTERNAL_ERROR.getMsg());
    }

    public static ResponseResult buildError(int status, int code, String msg) {
        return new ResponseResult(status, code, msg);
    }

    public static ResponseResult buildError(SysBusinessException sysException) {
        return new ResponseResult(sysException.getStatus(), sysException.getCode(), sysException.getMessage());
    }

    public static ResponseResult buildError(int status, String msg, Object data) {
        return new ResponseResult(status, msg, data);
    }


    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseResult{" +
                "status=" + status +
                ", code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
